import mongoose from 'mongoose';
import { DB_URI, DB_OPTIONS } from './dbConfig';

const connectDB = async (): Promise<void> => {
  try {
    await mongoose.connect(DB_URI, DB_OPTIONS);
    console.log('MongoDB connected successfully');
    console.log(`Database: ${DB_URI.includes('localhost') ? 'Local Development DB' : 'Cloud DB'}`);
  } catch (error) {
    console.error('MongoDB connection error:', error);
    console.error('Connection string:', DB_URI.replace(/mongodb\+srv:\/\/([^:]+):([^@]+)@/, 'mongodb+srv://$1:****@'));
    process.exit(1);
  }
};

export default connectDB; 